package ca.venasse.pinventory.common;

import java.io.Serializable;

import javax.persistence.Embeddable;

@Embeddable
public class Quantity implements Serializable {

	private static final long serialVersionUID = 1L;

	public static Quantity create(long value) {
		return new Quantity(value);
	}

	private long value;

	protected Quantity() {
	}

	private Quantity(long value) {
		this.value = value;
	}

	public long asLong() {
		return this.value;
	}

	public String asString() {
		return String.valueOf(this.value);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Quantity)) {
			return false;
		}
		Quantity other = (Quantity) obj;
		if (this.value != other.value) {
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (this.value ^ this.value >>> 32);
		return result;
	}

	public Quantity less(Quantity value) {
		return new Quantity(this.value - value.value);
	}

	public Quantity plus(Quantity value) {
		return new Quantity(this.value + value.value);
	}

}
